/**
 * 
 */
package systole.view.crud.tableModels;

import java.util.List;

import systole.domain.clinicalInformation.Pathology;
import systole.domain.clinicalInformation.PathologyPatient;
import systole.view.messages.EntityDescriptions;

/**
 * @author jmj
 * 
 */
public class PathologiesByPatientTableModel extends SystoleTableModel<PathologyPatient> {

    private String[] columnNames = {EntityDescriptions.PATHOLOGY, "Heredada",
        "Presente actualmente", "Desde hace [años]"};
    private static final int PATHOLOGY_INDEX = 0;
    private static final int INHERITED_INDEX = 1;
    private static final int CURRENTLY_INDEX = 2;
    private static final int AGE_AT_START = 3;

    /**
     * @param pathologies
     *
     */
    public PathologiesByPatientTableModel(List<PathologyPatient> pathologies) {
        super(pathologies);
    }


    /*
     * (non-Javadoc)
     *
     * @see javax.swing.table.TableModel#getColumnClass(int)
     */
    @Override
    public Class<?> getColumnClass(int columnIndex) {
        switch (columnIndex) {
            case PATHOLOGY_INDEX:
                return Pathology.class;
            case INHERITED_INDEX:
                return String.class;
            case CURRENTLY_INDEX:
                return String.class;
            case AGE_AT_START:
                return Integer.class;
        }
        return null;
    }

    /*
     * (non-Javadoc)
     *
     * @see javax.swing.table.TableModel#getColumnCount()
     */
    @Override
    public int getColumnCount() {
        return this.columnNames.length;
    }

    /*
     * (non-Javadoc)
     *
     * @see javax.swing.table.TableModel#getColumnName(int)
     */
    @Override
    public String getColumnName(int columnIndex) {
        return this.columnNames[columnIndex];
    }


    /*
     * (non-Javadoc)
     *
     * @see javax.swing.table.TableModel#getValueAt(int, int)
     */
    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        switch (columnIndex) {
            case PATHOLOGY_INDEX:
                return this.entities.get(rowIndex).getPathology();
            case INHERITED_INDEX:
                return (this.entities.get(rowIndex).getInherited() == null ? "No"
                        : (this.entities.get(rowIndex).getInherited().booleanValue() ? "Si" : "No"));
            case CURRENTLY_INDEX:
                return (this.entities.get(rowIndex).getCurrently() == null ? "No"
                        : (this.entities.get(rowIndex).getCurrently().booleanValue() ? "Si" : "No"));
            case AGE_AT_START:
                return this.entities.get(rowIndex).getAgeAtStartAsInteger();

        }
        return null;
    }

    /*
     * (non-Javadoc)
     *
     * @see javax.swing.table.TableModel#setValueAt(java.lang.Object, int, int)
     */
    @Override
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
        switch (columnIndex) {
            case PATHOLOGY_INDEX:
                this.entities.get(rowIndex).setPathology((Pathology) aValue);
                break;
            case INHERITED_INDEX:
                boolean inherited = "Si".equals(aValue);
                this.entities.get(rowIndex).setInherited(inherited);
                break;
            case CURRENTLY_INDEX:
                boolean currently = "Si".equals(aValue);
                this.entities.get(rowIndex).setCurrently(currently);
                break;
            case AGE_AT_START:
                this.entities.get(rowIndex).setAgeAtStartAsInteger((Integer) aValue);
        }
    }
}
